<?php
//
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
$merchid=$_RQ['id']?:$_RQ['merchid'];
if($merchid){
	$_SESSION['merchid']=$merchid;
}
$merchid=$merchid?:$_SESSION['onemerchid'];
$merchid=$merchid?:$_SESSION['merchid'];
$myshop=pdo_get('jy_merch_user',array('id'=>$merchid));
if($_RQ['op']=='main'){
	$return['pluginset']['merchfooternav']=$this->model('diy')->merchfooternav($merchid,$return['pluginset']);
	$return['params']=array();
	$return['groupset']=$this->plugin_setting('groupset');
	if($_RQ['pid']){
		$return['pid']=$return['oneid']=$_RQ['pid'];
	}else{
		$return['pid']=0;
	}
	$parentid=0;
	if($return['shopset']['level']){
		$return['islevel3']=true;
		$groupspram=array('onepluginname OR'=>'onepluginname=\'jy_merch\' or onepluginname=\'\' ','merchid'=>$merchid,'uniacid'=>$_SESSION['uniacid'],'isshow'=>'1','parentid'=>0);
		$onegroups=pdo_getall('jy_weishop_goods_group',$groupspram,array(),'','paixu desc');
		foreach($onegroups as &$ov){
			$ov['childs']=pdo_getall('jy_weishop_goods_group',array('onepluginname OR'=>'onepluginname=\'jy_merch\' or onepluginname=\'\' ','merchid'=>$merchid,'uniacid'=>$_SESSION['uniacid'],'isshow'=>1,'parentid'=>$ov['id']),array(),'','paixu desc');
			if(!$return['oneid']){			
				$return['oneid']=$ov['id'];
			}
			foreach($ov['childs'] as &$v3){
				$v3['childs']=pdo_getall('jy_weishop_goods_group',array('onepluginname OR'=>'onepluginname=\'jy_merch\' or onepluginname=\'\' ','merchid'=>$merchid,'uniacid'=>$_SESSION['uniacid'],'isshow'=>1,'parentid'=>$v3['id']),array(),'','paixu desc');
			}
		}
		$parentid=$onegroups[0]['id'];
	}
	$return['onegroups']=$onegroups;
	$groupspram=array('onepluginname OR'=>'onepluginname=\'jy_merch\' or onepluginname=\'\' ','merchid'=>$merchid,'uniacid'=>$_SESSION['uniacid'],'isshow'=>1,'parentid'=>$parentid);
	if($parentid){
		//$return['pid']=0;
	}
	$category=pdo_getall('jy_weishop_goods_group',$groupspram,array(),'','paixu desc');
	foreach($category as &$item){
		$item['childs']=pdo_getall('jy_weishop_goods_group',array('onepluginname OR'=>'onepluginname=\'jy_merch\' or onepluginname=\'\' ','mid'=>$myshop['mid'],'uniacid'=>$_SESSION['uniacid'],'isshow'=>1,'parentid'=>$item['id']),array(),'','paixu desc');
		if(!$return['pid']){			
			$return['pid']=$item['id'];
			$return['childs']=$item['childs'];
			$return['nowkey']=0;
			$return['nowchilds']=$item['childs'];
			if(!$parentid){
				$return['params']['pcate']=$return['pid']?:$category[0]['id'];
				$return['params']['ccate']=$item['childs'][0]['id'];
			}else{
				$return['params']['pcate']=$parentid;
				$return['params']['ccate']=$return['pid']?:$category[0]['id'];
				$return['params']['scate']=$item['childs'][0]['id'];
			}
			$return['nowchildid']=$item['childs'][0]['id'];
		}
	}
	$searchkeyword=$this->plugin_setting('search')['keyword'];
	$return['searchkeyword']=explode(';',$searchkeyword);
	$return['category']=$category;
	//推荐
	$groupspram['isrecommand']=1;
	$recommend=pdo_getall('jy_weishop_goods_group',$groupspram);
	$return['recommend']=$recommend;
	if(count($recommend) && !$return['shopset']['level']){
		//$return['childs']=$recommend;
		//$return['pid']=0;
	}
	set_html('title',$myshop['merchname']);
	$return['sharedata']=array(
		'title'=>$myshop['merchname'],
		'desc'=>$myshop['desc']?:'在线商城，一个属于自己的个人商城！',
		'link'=>custom_url('jy_merch/shop.groups//merchid='.$merchid.'&fromuser='.$_SESSION['uid'],true),
		'imgUrl'=>ATTACHMENT_URL.$myshop['logo']
	);
	exi($return);
}
?>